package com.rabbit.fanoutdemo.controller;

import com.rabbit.fanoutdemo.config.FanoutConfig;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SendMessage {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @RequestMapping("/send")
    public String sendMessage(){
        //                              交换机名称                   路由key，但fanout没有  消息体
        rabbitTemplate.convertAndSend(FanoutConfig.FANOUT_EXCHANGE,"","fanout message");
        //消息体是个object ， 可以是自定义对象 ，但是接受的时候也要按类型接收
        return "success";
    }
}
